package com.longxi.tianjintianbao.ui.activity.houseinspection;

import android.content.Intent;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.RequiresApi;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.ui.adapter.FullyGridLayoutManager;
import com.longxi.tianjintianbao.ui.adapter.GridImageNoChangeAdapter;
import com.longxi.tianjintianbao.ui.base.BaseActivity;
import com.longxi.tianjintianbao.ui.presenter.houseinspection.AssetsCheckAtPresenter;
import com.longxi.tianjintianbao.ui.view.houseinspection.IAssetsCheckAtView;
import com.longxi.tianjintianbao.utils.AddPicUtils;
import com.longxi.tianjintianbao.utils.GlobalUtils;
import com.luck.picture.lib.entity.LocalMedia;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 入住验房里面有一个个小项目 这些项目都可以点击查看或检查 这个是查看用
 * Created by cxw on & 2018/9/20
 */
public class AssetsCheckDetailActivity extends BaseActivity {

    @BindView(R.id.recyclerView)
    RecyclerView mRecyclerView;

    private List<LocalMedia> selectList;
    private AddPicUtils addPicUtils;
    private GridImageNoChangeAdapter gridImageAdapter;

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_assets_check_detail;
    }

    @Override
    protected AssetsCheckAtPresenter createPresenter() {
        return new AssetsCheckAtPresenter(this);
    }

    @Override
    public void initView() {
        super.initView();
        setTitle("验房详情");
        setTvLeft("返回");
    }

    @Override
    public void initData() {
        super.initData();
        initImage();
        handler.sendEmptyMessage(0);
    }

    /**
     * 初始化图片数据
     */
    private void initImage() {
        selectList = new ArrayList<>();
        selectList.add(new LocalMedia("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1535782696856&di=e1d2395c7a9db7ccc1b043aa38489acb&imgtype=0&src=http%3A%2F%2Fa.hiphotos.baidu.com%2Fzhidao%2Fpic%2Fitem%2F21a4462309f79052782f28490ff3d7ca7bcbd591.jpg", 0, 0, ""));
        selectList.add(new LocalMedia("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1535782696856&di=e1d2395c7a9db7ccc1b043aa38489acb&imgtype=0&src=http%3A%2F%2Fa.hiphotos.baidu.com%2Fzhidao%2Fpic%2Fitem%2F21a4462309f79052782f28490ff3d7ca7bcbd591.jpg", 0, 0, ""));
        selectList.add(new LocalMedia("http://img2.tgbusdata.cn/v2/thumb/jpg/NDY0LDYwMCwyNDAsNCwzLDEsLTEsMCx0cjY1/u/3ds.tgbus.bnbsky.com/UploadFiles/201808/2018080609550058.jpg", 0, 0, ""));
    }

    private Handler handler = new Handler() {
        @RequiresApi(api = Build.VERSION_CODES.KITKAT)
        @Override
        public void handleMessage(Message msg) {
        switch (msg.what) {
            case 0:
                addPicUtils = new AddPicUtils(AssetsCheckDetailActivity.this);
                addPicUtils.maxSelectNum = selectList.size();
                gridImageAdapter = new GridImageNoChangeAdapter(AssetsCheckDetailActivity.this, addPicUtils.onAddPicClickListener2);
                addPicUtils.selectList = selectList;
                gridImageAdapter.setList(addPicUtils.selectList);
                gridImageAdapter.setW(GlobalUtils.getGridWidth());
                gridImageAdapter.setSelectMax(addPicUtils.maxSelectNum);
                mRecyclerView.setAdapter(gridImageAdapter);
                FullyGridLayoutManager manager = new FullyGridLayoutManager(AssetsCheckDetailActivity.this, 3, GridLayoutManager.VERTICAL, false);
                mRecyclerView.setLayoutManager(manager);
                break;
        }
        }
    };

}
